<template>
  <div>
    <el-card>
      <el-page-header icon="" content="首页" title="企业门户管理系统">
      </el-page-header>
      <el-card class="box-card">
        <el-row>
          <el-col :span="4">
            <el-avatar :size="80" :src="avatarUrl" />
          </el-col>
          <el-col :span="20">
            <h3 style="line-height: 80px">
              欢迎回来，{{ store.state.userInfo.userName }}，{{ wellcomeText }}
            </h3>
          </el-col>
        </el-row>
      </el-card>
      <el-card class="box-card">
        <template #header>
          <div class="card-header">
            <span>公司产品</span>
          </div>
        </template>
        <el-carousel :interval="4000" type="card" height="200px">
          <el-carousel-item v-for="item in tableData" :key="item._id">
            <div
              :style="{
                backgroundImage: `url(http://localhost:3000${item.cover})`,
                backgroundSize: '100%'
              }"
            >
              <h3 text="2xl" justify="center">{{ item.title }}</h3>
            </div>
          </el-carousel-item>
        </el-carousel>
      </el-card>
    </el-card>
  </div>
</template>

<script setup>
import axios from 'axios'
import { useStore } from 'vuex'
import { computed, reactive } from 'vue'
import { onMounted, ref } from 'vue'

const store = useStore()
const tableData = ref([])
// console.log(store.state)
onMounted(() => {
  getTableData()
})

const getTableData = async () => {
  const res = await axios.post(`/adminApi/product/list`, {
    creater: store.state.userInfo.userName
  })
  if (res.data.code === '0000') {
    tableData.value = res.data.data
  }
}

const avatarUrl = computed(() =>
  store.state.userInfo.avatar
    ? 'http://localhost:3000' + store.state.userInfo.avatar
    : `https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png`
)
const wellcomeText = computed(() =>
  new Date().getHours() < 12
    ? '要开心每一天！'
    : '你可能累了，喝杯咖啡提提神吧！'
)
</script>

<style lang="scss" scoped>
.box-card {
  margin-top: 16px;
}
.el-carousel__item h3 {
  color: #fff;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
